package god.dao01;

/**
 * @author wang hao
 * @date 2023-02-18 10:35
 *  在arr上 找到 >= value的 最左位置
 *
 *    二分到底
 */
public class Demo02 {

    public static int nearrestIndex(int[] arr, int value){
        int L = 0, R = arr.length - 1;
        int index = -1;
        while (L <= R){
            int mid = L + ((R - L) >> 1);
            if (arr[mid] >= value){
                index = mid;
                R = mid - 1;
            }else {
                L = mid + 1;
            }
        }
        return index;
    }


    public static void main(String[] args) {
        int[] arr = new int[]{1,2,3,3,4,5,6};
        int i = Demo02.nearrestIndex(arr, 3);
        System.out.println(i);
    }
}
